import 图形界面.*;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.List;

public class DormSystem {
    //图一框架
    private JFrame frame1=new JFrame("登入界面");
    private JLabel UserName=new JLabel("用户名");
    private JTextField UserName1=new JTextField(80);
    private JLabel Possword=new JLabel("密码");
    private JTextField Possword1=new JTextField(80);
    private JButton but1=new JButton("确定");
    private JButton but2=new JButton("注册");
    private JRadioButton jrb1=new JRadioButton("学生");
    private JRadioButton jbr2=new JRadioButton("管理员");

    //图二框架
    private JFrame frame2=new JFrame("注册界面");
    private JLabel account=new JLabel("请输入你的账号");
    private JTextField account1=new JTextField(80);
    private JLabel possword1=new JLabel("请输入你的密码");
    private JTextField posswordA=new JTextField(80);
    private JLabel possword2=new JLabel("再次输入你的密码");
    private JTextField posswordB=new JTextField(80);
    private JLabel name=new JLabel("请输入你的姓名");
    private JTextField name1=new JTextField(80);
    private JButton but3=new JButton("确定");

    //图三框架
    private JFrame frame3=new JFrame("注册成功");
    private JLabel chengg=new JLabel("已成功注册账号");
    private JButton but4=new JButton("确定");

    //图四框架
    private JFrame frame4=new JFrame();
    private JLabel Opdorm=new JLabel("选择宿舍");
    private JButton Opdorm1=new JButton("进入");
    private JLabel UpMix=new JLabel("报修");
    private JButton UpMix1=new JButton("进入");

    //图六框架(宿舍楼分布图)有时间记得把校园图做出来
    private JFrame frame6=new JFrame("宿舍楼分布图");
    private JButton built1=new JButton("一栋");
    private JButton built2=new JButton("二栋");

    //图九框架(楼1宿舍分布)
    private JFrame frame9=new JFrame("楼1宿舍分布");
    private JButton dorm1=new JButton("宿舍1-101");
    private JButton dorm2=new JButton("宿舍1-102");
    private JButton dorm3=new JButton("宿舍1-201");
    private JButton dorm4=new JButton("宿舍1-202");

    //图十框架(楼2宿舍分布)
    private JFrame frame10=new JFrame("楼2宿舍分布");
    private JButton dorm5=new JButton("宿舍2-101");
    private JButton dorm6=new JButton("宿舍2-102");

    //图十一框架(1-101床位分布)
    private JFrame frame11=new JFrame("1-101");
    private JButton bed1=new JButton("床1");
    private JButton bed2=new JButton("床2");
    private JButton bed3=new JButton("床3");

    //图十二框架(1-102)
    private JFrame frame12=new JFrame("1-102");
    private JButton bed4=new JButton("床4");
    private JButton bed5=new JButton("床5");

    //图十三框架(1-201)
    private JFrame frame13=new JFrame("1-201");
    private JButton bed6=new JButton("床6");
    private JButton bed7=new JButton("床7");

    //图十四框架(1-202)
    private JFrame frame14=new JFrame("1-202");
    private JButton bed8=new JButton("床8");
    private JButton bed9=new JButton("床9");

    //图十五框架(2-101)
    private JFrame frame15=new JFrame("2-101");
    private JButton bed10=new JButton("床10");
    private JButton bed11=new JButton("床11");

    //图十六框架(2-102)
    private JFrame frame16=new JFrame("2-102");
    private JButton bed12=new JButton("床12");
    private JButton bed13=new JButton("床13");

    //图十八框架(管理员管理面版)
    private JFrame frame18=new JFrame("管理面版");
    private JMenuBar jmb = new JMenuBar();
    private JMenu menuFile=new JMenu("文件");
    private JMenu menuOp=new JMenu("操作");
    private JMenu menuFix=new JMenu("报修信息");
    private JMenuItem menuItemDelete=new JMenuItem("删除");
    private JMenuItem menuItemChange=new JMenuItem("更改");
    private JMenuItem menuItemFindSutdent=new JMenuItem("查找");
    private JMenuItem menuItemFixInfor=new JMenuItem("查看");

    //图二十五框架
    private JFrame frame25=new JFrame("双击报修原因列的格子删除信息，表示已经去维修了");

    public DormSystem(){
        frame1.setSize(550,400);
        frame1.setLocation(500,200);
        frame1.setLayout(null);
        UserName.setBounds(100,60,200,20);
        UserName1.setBounds(200,60,200,20);
        Possword.setBounds(100,100,200,20);
        Possword1.setBounds(200,100,200,20);
        but1.setBounds(160,150,100,20);
        but2.setBounds(260,150,100,20);
        jrb1.setBounds(160,200,100,20);
        jbr2.setBounds(260,200,100,20);
        frame1.add(UserName);
        frame1.add(UserName1);
        frame1.add(Possword);
        frame1.add(Possword1);
        frame1.add(but1);
        frame1.add(but2);
        ButtonGroup bg=new ButtonGroup();
        bg.add(jrb1);
        bg.add(jbr2);
        frame1.add(jrb1);
        frame1.add(jbr2);
        frame1.setVisible(true);
        //学生端入口
        jrb1.addActionListener(e->{
            //点击注册
            but2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    frame1.setVisible(false);
                    //设计框架2（注册界面）的页面

                    frame2.setSize(550, 400);
                    frame2.setLocation(500, 200);

                    frame2.setLayout(null);
                    account.setBounds(100, 60, 200, 20);
                    account1.setBounds(200, 60, 200, 20);
                    possword1.setBounds(100, 100, 200, 20);
                    posswordA.setBounds(200, 100, 200, 20);
                    possword2.setBounds(100, 140, 200, 20);
                    posswordB.setBounds(200, 140, 200, 20);
                    name.setBounds(100, 180, 200, 20);
                    name1.setBounds(200, 180, 200, 20);
                    but3.setBounds(200, 220, 100, 20);
                    frame2.add(account);
                    frame2.add(account1);
                    frame2.add(possword1);
                    frame2.add(possword2);
                    frame2.add(posswordA);
                    frame2.add(posswordB);
                    frame2.add(name);
                    frame2.add(name1);
                    frame2.add(but3);
                    frame2.setVisible(true);
                    //将新建的账号密码存入saccount表,告诉你注册完成，返回至框架1
                    but3.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            String ZhangHao = account1.getText();
                            String MiMa = posswordA.getText();
                            String Name1 = name1.getText();
                            try {
                                JDBC1.save1(ZhangHao, MiMa, Name1);
                            } catch (Exception ex) {
                                throw new RuntimeException(ex);
                            }
                            frame2.setVisible(false);
                            frame3.setSize(550, 400);
                            frame3.setLocation(500, 200);
                            frame3.setLayout(new FlowLayout());
                            frame3.add(chengg);
                            frame3.add(but4);
                            frame3.setVisible(true);
                            //在注册成功界面按下确认按钮后返回界面1
                            but4.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    frame3.setVisible(false);
                                    frame1.setVisible(true);
                                }
                            });
                            frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        }
                    });

                    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                }
            });
            //点击确认
            but1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean temp;
                    String Account1 = UserName1.getText();
                    String Pw1 = Possword1.getText();
                    try {
                        temp = JDBC1.find1(Account1, Pw1);
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                    //账号密码正确
                    if (temp == true) {
                        frame1.setVisible(false);
                        frame4.setSize(550, 400);
                        frame4.setLocation(500, 200);
                        frame4.setExtendedState(JFrame.MAXIMIZED_BOTH);
                        frame4.setLayout(new FlowLayout());
                        frame4.add(Opdorm);
                        frame4.add(Opdorm1);
                        frame4.add(UpMix);
                        frame4.add(UpMix1);
                        frame4.setVisible(true);
                        //设计饿汉式单例模式
                        Person person=Person.getInstance();
                        try {
                            person.saveFile1(Account1);
                        } catch (Exception ex) {
                            throw new RuntimeException(ex);
                        }
                        //选择宿舍楼
                        Opdorm1.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                frame4.setVisible(false);
                                frame6.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                frame6.setLayout(new GridLayout(1, 2));
                                frame6.add(built1);
                                frame6.add(built2);
                                frame6.setVisible(true);

                                //点击楼1
                                built1.addActionListener(new ActionListener() {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        frame6.setVisible(false);
                                        frame9.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                        frame9.setLayout(new GridLayout(1, 4));
                                        frame9.add(dorm1);
                                        frame9.add(dorm2);
                                        frame9.add(dorm3);
                                        frame9.add(dorm4);
                                        frame9.setVisible(true);
                                        //选择宿舍1-101
                                        dorm1.addActionListener(new ActionListener() {
                                            @Override
                                            public void actionPerformed(ActionEvent e) {
                                                frame9.setVisible(false);
                                                frame11.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                                frame11.setLayout(new GridLayout(1, 3));
                                                frame11.add(bed1);
                                                frame11.add(bed2);
                                                frame11.add(bed3);
                                                frame11.setVisible(true);
                                                //选择1-101-1
                                                bed1.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
//                                                        duoxianc.button1(bed1);
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm1.getText();
                                                        String Bed1 = bed1.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                //选择1-101-2
                                                bed2.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm1.getText();
                                                        String Bed1 = bed2.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                //选择1-101-3
                                                bed3.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm1.getText();
                                                        String Bed1 = bed3.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                frame11.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            }
                                        });
                                        //选择宿舍1-102
                                        dorm2.addActionListener(new ActionListener() {
                                            @Override
                                            public void actionPerformed(ActionEvent e) {
                                                frame9.setVisible(false);
                                                frame12.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                                frame12.setLayout(new GridLayout(1, 2));
                                                frame12.add(bed4);
                                                frame12.add(bed5);
                                                frame12.setVisible(true);
                                                //选择1-102-1
                                                bed4.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm2.getText();
                                                        String Bed1 = bed4.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                //选择1-102-2
                                                bed5.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm2.getText();
                                                        String Bed1 = bed5.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                frame12.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            }
                                        });
                                        //选择宿舍1-201
                                        dorm3.addActionListener(new ActionListener() {
                                            @Override
                                            public void actionPerformed(ActionEvent e) {
                                                frame9.setVisible(false);
                                                frame13.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                                frame13.setLayout(new GridLayout(1, 2));
                                                frame13.add(bed6);
                                                frame13.add(bed7);
                                                frame13.setVisible(true);
                                                //选择1-201-1
                                                bed6.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm3.getText();
                                                        String Bed1 = bed6.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                //选择1-201-2
                                                bed7.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm3.getText();
                                                        String Bed1 = bed7.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                frame13.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            }
                                        });
                                        //选择宿舍1-202
                                        dorm4.addActionListener(new ActionListener() {
                                            @Override
                                            public void actionPerformed(ActionEvent e) {
                                                frame9.setVisible(false);
                                                frame14.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                                frame14.setLayout(new GridLayout(1, 2));
                                                frame14.add(bed8);
                                                frame14.add(bed9);
                                                frame14.setVisible(true);
                                                //选择1-202-1
                                                bed8.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm4.getText();
                                                        String Bed1 = bed8.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                //选择1-202-2
                                                bed9.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built1.getText();
                                                        String DORM1 = dorm4.getText();
                                                        String Bed1 = bed9.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                frame14.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            }
                                        });
                                        frame9.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                    }
                                });

                                //点击楼2
                                built2.addActionListener(new ActionListener() {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        frame6.setVisible(false);
                                        frame10.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                        frame10.setLayout(new GridLayout(1, 2));
                                        frame10.add(dorm5);
                                        frame10.add(dorm6);
                                        frame10.setVisible(true);
                                        //选择宿舍2-101
                                        dorm5.addActionListener(new ActionListener() {
                                            @Override
                                            public void actionPerformed(ActionEvent e) {
                                                frame9.setVisible(false);
                                                frame15.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                                frame15.setLayout(new GridLayout(1, 2));
                                                frame15.add(bed10);
                                                frame15.add(bed11);
                                                frame15.setVisible(true);
                                                //选择2-101-1
                                                bed10.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built2.getText();
                                                        String DORM1 = dorm5.getText();
                                                        String Bed1 = bed10.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                //选择2-101-2
                                                bed11.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built2.getText();
                                                        String DORM1 = dorm5.getText();
                                                        String Bed1 = bed11.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                frame15.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            }
                                        });
                                        //选择宿舍2-102
                                        dorm6.addActionListener(new ActionListener() {
                                            @Override
                                            public void actionPerformed(ActionEvent e) {
                                                frame9.setVisible(false);
                                                frame16.setExtendedState(JFrame.MAXIMIZED_BOTH);
                                                frame16.setLayout(new GridLayout(1, 2));
                                                frame16.add(bed12);
                                                frame16.add(bed13);
                                                frame16.setVisible(true);
                                                //选择2-102-1
                                                bed12.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built2.getText();
                                                        String DORM1 = dorm6.getText();
                                                        String Bed1 = bed12.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                //选择2-102-2
                                                bed13.addActionListener(new ActionListener() {
                                                    @Override
                                                    public void actionPerformed(ActionEvent e) {
                                                        frame11.setVisible(false);
                                                        String ACCOUNT1 = account1.getText();
                                                        String SNAME = null;
                                                        try {
                                                            SNAME = JDBC1.getSname(UserName1.getText());
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        String BUILT1 = built2.getText();
                                                        String DORM1 = dorm6.getText();
                                                        String Bed1 = bed13.getText();
                                                        try {
                                                            JDBC1.save3(SNAME, BUILT1, DORM1, Bed1);
                                                        } catch (Exception ex) {
                                                            throw new RuntimeException(ex);
                                                        }
                                                        new ChooseBedSuccess();
                                                    }
                                                });
                                                frame16.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                            }
                                        });
                                        frame10.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                    }
                                });
                                frame6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                            }
                        });
                        //点击报修
                        UpMix1.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                frame4.setVisible(false);
                                new UpFixGrid();
                            }
                        });
                        frame4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    }
                    //当账号密码错误
                    else {
                        frame1.setVisible(false);
                        new accountError();
                    }
                }
            });
            frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        });

        //管理员端入口
        jbr2.addActionListener(e->{
            //点击注册
            but2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    frame1.setVisible(false);
                    //设计框架2（注册界面）的页面

                    frame2.setSize(550, 400);
                    frame2.setLocation(500, 200);

                    frame2.setLayout(null);
                    account.setBounds(100, 60, 200, 20);
                    account1.setBounds(200, 60, 200, 20);
                    possword1.setBounds(100, 100, 200, 20);
                    posswordA.setBounds(200, 100, 200, 20);
                    possword2.setBounds(100, 140, 200, 20);
                    posswordB.setBounds(200, 140, 200, 20);
                    name.setBounds(100, 180, 200, 20);
                    name1.setBounds(200, 180, 200, 20);
                    but3.setBounds(200, 220, 100, 20);
                    frame2.add(account);
                    frame2.add(account1);
                    frame2.add(possword1);
                    frame2.add(possword2);
                    frame2.add(posswordA);
                    frame2.add(posswordB);
                    frame2.add(name);
                    frame2.add(name1);
                    frame2.add(but3);
                    frame2.setVisible(true);
                    //将新建的账号密码存入account表,告诉你注册完成，返回至框架1
                    but3.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            String ZhangHao = account1.getText();
                            String MiMa = posswordA.getText();
                            String Name1 = name1.getText();
                            try {
                                JDBC1.save4(ZhangHao, MiMa, Name1);
                            } catch (Exception ex) {
                                throw new RuntimeException(ex);
                            }
                            frame2.setVisible(false);
                            frame3.setSize(550, 400);
                            frame3.setLocation(500, 200);
                            frame3.setLayout(new FlowLayout());
                            frame3.add(chengg);
                            frame3.add(but4);
                            frame3.setVisible(true);
                            //在注册成功界面按下确认按钮后返回界面1
                            but4.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    frame3.setVisible(false);
                                    frame1.setVisible(true);
                                }
                            });
                            frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        }
                    });

                    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                }
            });
            //点击确定
            but1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean temp;
                    String Account1 = UserName1.getText();
                    String Pw1 = Possword1.getText();
                    //验证是否正确
                    try {
                        temp = JDBC1.find2(Account1, Pw1);
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                    //当账号密码正确
                    if(temp==true){
                        frame1.setVisible(false);
                        frame18.setExtendedState(JFrame.MAXIMIZED_BOTH);
                        DefaultTableModel dtm=new DefaultTableModel();
                        dtm.addColumn("姓名");
                        dtm.addColumn("栋");
                        dtm.addColumn("宿舍号");
                        dtm.addColumn("床位");
                        drom101 drom102 = new drom101();
                        //从数据库中拿数据
                        try {
                            List<drom101> list1=drom102.GetInforDrom();
                            for(drom101 drom103:list1){
                                //103是类
                                dtm.addRow(new Object[]{drom103.getSname(),drom103.getBuiltNum(),drom103.getDormNum(),drom103.getBedNum()});
                            }
                        } catch (Exception ex) {
                            throw new RuntimeException(ex);
                        }
                        JTable table = new JTable(dtm);
                        table.setRowHeight(30);
                        JScrollPane jsp = new JScrollPane(table);
                        frame18.add(jsp);
                        //菜单
                        frame18.setJMenuBar(jmb);
                        jmb.add(menuFile);
                        jmb.add(menuOp);
                        jmb.add(menuFix);
                        menuOp.add(menuItemDelete);
                        menuOp.add(menuItemChange);
                        menuOp.add(menuItemFindSutdent);
                        menuFix.add(menuItemFixInfor);
                        //点击删除
                        menuItemDelete.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                frame18.setVisible(false);
                                new deleteSDrom();
                            }
                        });
                        //点击更改
                        menuItemChange.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                frame18.setVisible(false);
                                new changeSDorm();
                            }
                        });
                        //点击查找
                        menuItemFindSutdent.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                frame18.setVisible(false);
                                new findSDorm();
                            }
                        });
                        //点击报修信息
                        menuItemFixInfor.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                frame18.setVisible(false);
                                frame25.setSize(550,400);
                                frame25.setLocation(500, 200);
                                frame25.setLayout(new FlowLayout());
                                DefaultTableModel dtm=new DefaultTableModel();
                                dtm.addColumn("姓名");
                                dtm.addColumn("栋");
                                dtm.addColumn("宿舍号");
                                dtm.addColumn("报修原因");
                                mix1 mx1=new mix1();
                                try {
                                    List<mix1> list1=mx1.GetInforMix();
                                    for(mix1 mx2:list1){
                                        dtm.addRow(new Object[]{mx2.getSname(),mx2.getBuiltnum(),mx2.getDormnum(),mx2.getReason()});
                                    }
                                } catch (Exception ex) {
                                    throw new RuntimeException(ex);
                                }
                                JTable table2=new JTable(dtm);
                                JScrollPane jsp = new JScrollPane(table2);
                                frame25.add(jsp);
                                //双击格子删除信息，表示已经去维修了
                                table2.addMouseListener(new MouseAdapter() {
                                    @Override
                                    public void mouseClicked(MouseEvent e) {
                                        // 获取鼠标点击的行和列
                                        int row = table2.rowAtPoint(e.getPoint());
                                        int column = table2.columnAtPoint(e.getPoint());

                                        // 检查是否是左键单击
                                        if (SwingUtilities.isLeftMouseButton(e) && row != -1 && column != -1) {
                                            String value = (String) table2.getModel().getValueAt(row, column);
                                            System.out.println("Clicked cell value: " + value);
                                            try {
                                                mix1.deleteMix(value);
                                            } catch (Exception ex) {
                                                throw new RuntimeException(ex);
                                            }
                                            // 从模型中删除选中的行
                                            dtm.removeRow(row);
                                        }
                                    }
                                });
                                frame25.setVisible(true);
                                frame25.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                            }
                        });
                        frame18.setVisible(true);
                        frame18.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    }
                    //当账号密码错误
                    else {
                        frame1.setVisible(false);
                        new accountError();
                    }
                }
            });
        });
    }
}

